<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>Rulebooks Template</title>
<link href="../docs-assets/Breadcrumbs.css" rel="stylesheet" rev="stylesheet" type="text/css">
		<meta name="viewport" content="width=device-width initial-scale=1">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="Content-Language" content="en-gb">

<link href="../docs-assets/Contents.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Progress.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Navigation.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Fonts.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Base.css" rel="stylesheet" rev="stylesheet" type="text/css">
<script>
MathJax = {
	tex: {
		inlineMath: '$', '$'], ['\\(', '\\)'
	},
	svg: {
		fontCache: 'global'
	}
};
</script>
<script type="text/javascript" id="MathJax-script" async
	src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js">
</script>

<link href="../docs-assets/Colours.css" rel="stylesheet" rev="stylesheet" type="text/css">
		
	</head>
	<body class="commentary-font">
		<nav role="navigation">
		<h1><a href="../index.html"><img src="../docs-assets/Inform.png" height=72> </a></h1>
<ul><li><a href="../index.html">home</a></li>
</ul><h2>Compiler</h2><ul>
<li><a href="../structure.html">structure</a></li>
<li><a href="../inbuildn.html">inbuild</a></li>
<li><a href="../inform7n.html">inform7</a></li>
<li><a href="../intern.html">inter</a></li>
<li><a href="../services.html">services</a></li>
<li><a href="../secrets.html">secrets</a></li>
</ul><h2>Other Tools</h2><ul>
<li><a href="../inblorbn.html">inblorb</a></li>
<li><a href="../inform6.html">inform6</a></li>
<li><a href="../inpolicyn.html">inpolicy</a></li>
</ul><h2>Resources</h2><ul>
<li><a href="../extensions.html">extensions</a></li>
<li><a href="../kits.html">kits</a></li>
</ul><h2>Repository</h2><ul>
<li><a href="https://github.com/ganelson/inform"><img src="../docs-assets/github.png" height=0> github</a></li>
</ul><h2>Related Projects</h2><ul>
<li><a href="https://github.com/ganelson/inweb"><img src="../docs-assets/github.png" height=0> inweb</a></li>
<li><a href="https://github.com/ganelson/intest"><img src="../docs-assets/github.png" height=0> intest</a></li>
</ul>
		</nav>
		<main role="main">
		<!-- Weave of 'Rulebooks Template' generated by inweb -->
<div class="breadcrumbs">
    <ul class="crumbs"><li><a href="../index.html">Home</a></li><li><a href="../extensions.html">Kits</a></li><li><a href="index.html">BasicInformKit</a></li><li><b>Rulebooks Template</b></li></ul></div>
<p class="purpose">To work through the rules in a rulebook until a decision is made.</p>

<ul class="toc"><li><a href="rltm.html#SP1">&#167;1. Latest Rule Result</a></li><li><a href="rltm.html#SP2">&#167;2. Following</a></li><li><a href="rltm.html#SP3">&#167;3. Specifying Outcomes</a></li><li><a href="rltm.html#SP4">&#167;4. Discovering Outcomes</a></li><li><a href="rltm.html#SP5">&#167;5. Casting</a></li><li><a href="rltm.html#SP6">&#167;6. Debugging</a></li><li><a href="rltm.html#SP7">&#167;7. The Default Rule and Rulebook</a></li></ul><hr class="tocbar">

<p class="commentary firstcommentary"><a id="SP1" class="paragraph-anchor"></a><b>&#167;1. Latest Rule Result.</b>This used to be a large data structure which kept track of the effect of
procedural rules, but in January 2011 procedurals were abolished. It retains
only one purpose: as a place to record the result of the most recently
completed rule. This used to sit on the top of the stack, and is now the
only thing which ever sits on it. So the "stack" has just one 3-word
record now. The meanings of these are as follows. The first word is one of
the following:
</p>

<ul class="items"><li>(1) <span class="extract"><span class="extract-syntax">RS_SUCCEEDS</span></span> indicates that the most recent rule or rulebook processed
ended in success. Word 2 is <span class="extract"><span class="extract-syntax">false</span></span> if there's no value, or the kind if there
is, in which case word 3 contains the value itself.
</li><li>(2) <span class="extract"><span class="extract-syntax">RS_FAILS</span></span> is similar, but for a failure. Note that failures can also
return values.
</li><li>(3) <span class="extract"><span class="extract-syntax">RS_NEITHER</span></span> is similar except that it cannot return any value, so that
words 2 and 3 are meaningless.
</li></ul>
<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">RS_NEITHER</span><span class="plain-syntax">     = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">RS_SUCCEEDS</span><span class="plain-syntax">    = </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">RS_FAILS</span><span class="plain-syntax">       = </span><span class="constant-syntax">2</span><span class="plain-syntax">;</span>

<span class="reserved-syntax">Array</span><span class="plain-syntax"> </span><span class="identifier-syntax">latest_rule_result</span><span class="plain-syntax"> --&gt; </span><span class="constant-syntax">3</span><span class="plain-syntax">;</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">RecordRuleOutcome</span><span class="plain-syntax"> </span><span class="identifier-syntax">usage</span><span class="plain-syntax"> </span><span class="identifier-syntax">strong_kind</span><span class="plain-syntax"> </span><span class="identifier-syntax">val</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">latest_rule_result</span><span class="plain-syntax">--&gt;0 == </span><span class="identifier-syntax">RS_SUCCEEDS</span><span class="plain-syntax"> </span><span class="reserved-syntax">or</span><span class="plain-syntax"> </span><span class="identifier-syntax">RS_FAILS</span><span class="plain-syntax">) &amp;&amp;</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">KindConformsTo_POINTER_VALUE_TY</span><span class="plain-syntax">(</span><span class="identifier-syntax">latest_rule_result</span><span class="plain-syntax">--&gt;1)))</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">DestroyPV</span><span class="plain-syntax">(</span><span class="identifier-syntax">latest_rule_result</span><span class="plain-syntax">--&gt;2);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">usage</span><span class="plain-syntax"> == </span><span class="identifier-syntax">RS_SUCCEEDS</span><span class="plain-syntax"> </span><span class="reserved-syntax">or</span><span class="plain-syntax"> </span><span class="identifier-syntax">RS_FAILS</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">KindConformsTo_POINTER_VALUE_TY</span><span class="plain-syntax">(</span><span class="identifier-syntax">strong_kind</span><span class="plain-syntax">)))</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">val</span><span class="plain-syntax"> = </span><span class="identifier-syntax">CopyPV</span><span class="plain-syntax">(</span><span class="identifier-syntax">CreatePV</span><span class="plain-syntax">(</span><span class="identifier-syntax">strong_kind</span><span class="plain-syntax">), </span><span class="identifier-syntax">val</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">latest_rule_result</span><span class="plain-syntax">--&gt;0 = </span><span class="identifier-syntax">usage</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">latest_rule_result</span><span class="plain-syntax">--&gt;1 = </span><span class="identifier-syntax">strong_kind</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">latest_rule_result</span><span class="plain-syntax">--&gt;2 = </span><span class="identifier-syntax">val</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP2" class="paragraph-anchor"></a><b>&#167;2. Following.</b>Until January 2011, there were two ways to invoke a rulebook: to "follow" it
or simply "process" it. With the demise of procedural rules, these became
equivalent.
</p>

<p class="commentary">In the early days of Inform 7, stack usage became a serious issue since
some forms of the Frotz Z-machine interpreter provided only 4K of stack
by default. ("Only" 4K. In the mid-1980s, one of the obstacles facing
IF authors at Infocom was the need to get the stack usage down to fewer
than 600 bytes in order that the story file could be run on the smaller
home computers of the day.) <span class="extract"><span class="extract-syntax">FollowRulebook</span></span> was the major consumer of
stack space, on average, because of its frequent recursion. Now that the
process is simpler, this has become less problematic, since the routine
now has fewer local variables.
</p>

<p class="commentary"><span class="extract"><span class="extract-syntax">FollowRulebook</span></span> takes three arguments, of which only the first is
compulsory:
</p>

<ul class="items"><li>(a) The <span class="extract"><span class="extract-syntax">rulebook</span></span> is an I7 value of kind "rule", which means it can be
either the ID number of a rulebook &mdash; from 0 up to \(N-1\), where \(N\) is the
number of rulebooks compiled by Inform, typically about 600 &mdash; or else the
address of a routine representing an individual rule.
</li><li>(b) The <span class="extract"><span class="extract-syntax">parameter</span></span> supplied to the rulebook. Much as arguments can be supplied
to a function in a conventional language's function call, so a parameter can be
supplied whenever a rulebook is invoked.
</li><li>(c) <span class="extract"><span class="extract-syntax">no_paragraph_skips</span></span> is a flag: if explicitly set <span class="extract"><span class="extract-syntax">true</span></span>, then the rulebook
is run with paragraph breaking suppressed. This is the process by which
paragraph division points are placed between rules, so that if two rules both
print text then a paragraph break appears between. While that is appropriate
for rulebooks attached to actions or for "every turn" rules, it is disastrous
for rulebooks attached to activities such as "printing the name of
something".
</li></ul>
<p class="commentary"><span class="extract"><span class="extract-syntax">FollowRulebook</span></span> returns <span class="extract"><span class="extract-syntax">R</span></span> if rule <span class="extract"><span class="extract-syntax">R</span></span> in the rulebook (or rule) chose to
"succeed" or "fail", and <span class="extract"><span class="extract-syntax">false</span></span> if it made no choice. (To repeat: if
the rule explicitly fails, then <span class="extract"><span class="extract-syntax">FollowRulebook</span></span> returns <span class="extract"><span class="extract-syntax">true</span></span>. It's easy
to write plausible-looking code which goes wrong because it assumes that the
return value is success vs. failure.) The outcome of <span class="extract"><span class="extract-syntax">FollowRulebook</span></span> is
stored as described above: thus the most recent rule or rulebook succeeded
or failed if &mdash;
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    (</span><span class="identifier-syntax">latest_rule_result</span><span class="plain-syntax">--&gt;0 == </span><span class="identifier-syntax">RS_SUCCEEDS</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    (</span><span class="identifier-syntax">latest_rule_result</span><span class="plain-syntax">--&gt;0 == </span><span class="identifier-syntax">RS_FAILS</span><span class="plain-syntax">)</span>
</pre>
<p class="commentary">and otherwise there was no decision.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">process_rulebook_count</span><span class="plain-syntax">; </span><span class="comment-syntax">Depth of processing recursion</span>
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">debugging_rules</span><span class="plain-syntax"> = </span><span class="reserved-syntax">false</span><span class="plain-syntax">; </span><span class="comment-syntax">Are we tracing rule invocations?</span>
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">rulebook_without_variables</span><span class="plain-syntax"> = -1; </span><span class="comment-syntax">WorldModelKit sets this to ACTION_PROCESSING_RB</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">FollowRulebook</span><span class="plain-syntax"> </span><span class="identifier-syntax">rulebook</span><span class="plain-syntax"> </span><span class="identifier-syntax">parameter</span><span class="plain-syntax"> </span><span class="identifier-syntax">no_paragraph_skips</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">rv</span><span class="plain-syntax"> </span><span class="identifier-syntax">ss</span><span class="plain-syntax"> </span><span class="identifier-syntax">spv</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">ss</span><span class="plain-syntax"> = </span><span class="identifier-syntax">self</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">Protect_I7_Arrays</span><span class="plain-syntax">--&gt;0 ~= </span><span class="constant-syntax">16339</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">Protect_I7_Arrays</span><span class="plain-syntax">--&gt;1 ~= </span><span class="constant-syntax">12345</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"^^*** Fatal programming error: I7 arrays corrupted ***^^"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        @</span><span class="reserved-syntax">quit</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">parameter</span><span class="plain-syntax">) { </span><span class="identifier-syntax">self</span><span class="plain-syntax"> = </span><span class="identifier-syntax">parameter</span><span class="plain-syntax">; </span><span class="identifier-syntax">parameter_object</span><span class="plain-syntax"> = </span><span class="identifier-syntax">parameter</span><span class="plain-syntax">; }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">spv</span><span class="plain-syntax"> = </span><span class="identifier-syntax">parameter_value</span><span class="plain-syntax">; </span><span class="identifier-syntax">parameter_value</span><span class="plain-syntax"> = </span><span class="identifier-syntax">parameter</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="comment-syntax">we won't need parameter again, so can reuse it</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">parameter</span><span class="plain-syntax"> = </span><span class="identifier-syntax">debugging_rules</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">debugging_rules</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">DebugRulebooks</span><span class="plain-syntax">(</span><span class="identifier-syntax">rulebook</span><span class="plain-syntax">, </span><span class="identifier-syntax">parameter</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">process_rulebook_count</span><span class="plain-syntax"> = </span><span class="identifier-syntax">process_rulebook_count</span><span class="plain-syntax"> + </span><span class="identifier-syntax">debugging_rules</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">rulebook</span><span class="plain-syntax"> &gt;= </span><span class="constant-syntax">0</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">rulebook</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">NUMBER_RULEBOOKS_CREATED</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">rv</span><span class="plain-syntax"> = </span><span class="identifier-syntax">rulebooks_array</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">rulebook</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">rv</span><span class="plain-syntax"> ~= </span><span class="identifier-syntax">EMPTY_RULEBOOK</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">rulebook</span><span class="plain-syntax"> ~= </span><span class="identifier-syntax">rulebook_without_variables</span><span class="plain-syntax">) </span><span class="identifier-syntax">MStack_CreateRBVars</span><span class="plain-syntax">(</span><span class="identifier-syntax">rulebook</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">say__p</span><span class="plain-syntax">) </span><span class="identifier-syntax">RulebookParBreak</span><span class="plain-syntax">(</span><span class="identifier-syntax">no_paragraph_skips</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">rv</span><span class="plain-syntax"> = </span><span class="identifier-syntax">rv</span><span class="plain-syntax">(</span><span class="identifier-syntax">no_paragraph_skips</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">rulebook</span><span class="plain-syntax"> ~= </span><span class="identifier-syntax">rulebook_without_variables</span><span class="plain-syntax">) </span><span class="identifier-syntax">MStack_DestroyRBVars</span><span class="plain-syntax">(</span><span class="identifier-syntax">rulebook</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">rv</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">say__p</span><span class="plain-syntax">) </span><span class="identifier-syntax">RulebookParBreak</span><span class="plain-syntax">(</span><span class="identifier-syntax">no_paragraph_skips</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">rv</span><span class="plain-syntax"> = </span><span class="identifier-syntax">rulebook</span><span class="plain-syntax">();</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">rv</span><span class="plain-syntax"> == </span><span class="constant-syntax">2</span><span class="plain-syntax">) </span><span class="identifier-syntax">rv</span><span class="plain-syntax"> = </span><span class="identifier-syntax">reason_the_action_failed</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">rv</span><span class="plain-syntax">) </span><span class="identifier-syntax">rv</span><span class="plain-syntax"> = </span><span class="identifier-syntax">rulebook</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">rv</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">debugging_rules</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">process_rulebook_count</span><span class="plain-syntax"> = </span><span class="identifier-syntax">process_rulebook_count</span><span class="plain-syntax"> - </span><span class="identifier-syntax">debugging_rules</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">process_rulebook_count</span><span class="plain-syntax"> &lt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">process_rulebook_count</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">spaces</span><span class="plain-syntax">(2*</span><span class="identifier-syntax">process_rulebook_count</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">latest_rule_result</span><span class="plain-syntax">--&gt;0 == </span><span class="identifier-syntax">RS_SUCCEEDS</span><span class="plain-syntax">) </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"[stopped: success]^"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">latest_rule_result</span><span class="plain-syntax">--&gt;0 == </span><span class="identifier-syntax">RS_FAILS</span><span class="plain-syntax">) </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"[stopped: fail]^"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">debugging_rules</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">process_rulebook_count</span><span class="plain-syntax"> = </span><span class="identifier-syntax">process_rulebook_count</span><span class="plain-syntax"> - </span><span class="identifier-syntax">debugging_rules</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">latest_rule_result</span><span class="plain-syntax">--&gt;0 = </span><span class="identifier-syntax">RS_NEITHER</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">debugging_rules</span><span class="plain-syntax"> = </span><span class="identifier-syntax">parameter</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">self</span><span class="plain-syntax"> = </span><span class="identifier-syntax">ss</span><span class="plain-syntax">; </span><span class="identifier-syntax">parameter_value</span><span class="plain-syntax"> = </span><span class="identifier-syntax">spv</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">rv</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">RulebookParBreak</span><span class="plain-syntax"> </span><span class="identifier-syntax">no_paragraph_skips</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">no_paragraph_skips</span><span class="plain-syntax"> == </span><span class="reserved-syntax">false</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">say__pc</span><span class="plain-syntax"> &amp; </span><span class="identifier-syntax">PARA_NORULEBOOKBREAKS</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">))</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">DivideParagraphPoint</span><span class="plain-syntax">();</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP3" class="paragraph-anchor"></a><b>&#167;3. Specifying Outcomes.</b>The following provide ways for rules to succeed, fail or decline to do
either.
</p>

<p class="commentary"><span class="extract"><span class="extract-syntax">SetRulebookOutcome</span></span> is a little different: it changes the outcome state
of the most recent rule completed, not the current one. (It's used only
when saving and restoring this in the actions machinery: rules should not
call it.)
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">ActRulebookSucceeds</span><span class="plain-syntax"> </span><span class="identifier-syntax">rule_id</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">rule_id</span><span class="plain-syntax">) </span><span class="identifier-syntax">reason_the_action_failed</span><span class="plain-syntax"> = </span><span class="identifier-syntax">rule_id</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">RulebookSucceeds</span><span class="plain-syntax">();</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">ActRulebookFails</span><span class="plain-syntax"> </span><span class="identifier-syntax">rule_id</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">rule_id</span><span class="plain-syntax">) </span><span class="identifier-syntax">reason_the_action_failed</span><span class="plain-syntax"> = </span><span class="identifier-syntax">rule_id</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">RulebookFails</span><span class="plain-syntax">();</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">RulebookSucceeds</span><span class="plain-syntax"> </span><span class="identifier-syntax">strong_kind</span><span class="plain-syntax"> </span><span class="identifier-syntax">value</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">RecordRuleOutcome</span><span class="plain-syntax">(</span><span class="identifier-syntax">RS_SUCCEEDS</span><span class="plain-syntax">, </span><span class="identifier-syntax">strong_kind</span><span class="plain-syntax">, </span><span class="identifier-syntax">value</span><span class="plain-syntax">);</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">RulebookFails</span><span class="plain-syntax"> </span><span class="identifier-syntax">strong_kind</span><span class="plain-syntax"> </span><span class="identifier-syntax">value</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">RecordRuleOutcome</span><span class="plain-syntax">(</span><span class="identifier-syntax">RS_FAILS</span><span class="plain-syntax">, </span><span class="identifier-syntax">strong_kind</span><span class="plain-syntax">, </span><span class="identifier-syntax">value</span><span class="plain-syntax">);</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">RuleHasNoOutcome</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">RecordRuleOutcome</span><span class="plain-syntax">(</span><span class="identifier-syntax">RS_NEITHER</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">);</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">SetRulebookOutcome</span><span class="plain-syntax"> </span><span class="identifier-syntax">a</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">latest_rule_result</span><span class="plain-syntax">--&gt;0 = </span><span class="identifier-syntax">a</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP4" class="paragraph-anchor"></a><b>&#167;4. Discovering Outcomes.</b>And here is how to tell what the results were.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">RulebookOutcome</span><span class="plain-syntax"> </span><span class="identifier-syntax">a</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">a</span><span class="plain-syntax"> = </span><span class="identifier-syntax">latest_rule_result</span><span class="plain-syntax">--&gt;0;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">a</span><span class="plain-syntax"> == </span><span class="identifier-syntax">RS_FAILS</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">a</span><span class="plain-syntax"> == </span><span class="identifier-syntax">RS_SUCCEEDS</span><span class="plain-syntax">)) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">a</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">RS_NEITHER</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">RulebookFailed</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">latest_rule_result</span><span class="plain-syntax">--&gt;0 == </span><span class="identifier-syntax">RS_FAILS</span><span class="plain-syntax">) </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">; </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">RulebookSucceeded</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">latest_rule_result</span><span class="plain-syntax">--&gt;0 == </span><span class="identifier-syntax">RS_SUCCEEDS</span><span class="plain-syntax">) </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">; </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">ResultOfRule</span><span class="plain-syntax"> </span><span class="identifier-syntax">RB</span><span class="plain-syntax"> </span><span class="identifier-syntax">V</span><span class="plain-syntax"> </span><span class="identifier-syntax">F</span><span class="plain-syntax"> </span><span class="identifier-syntax">K</span><span class="plain-syntax"> </span><span class="identifier-syntax">a</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">RB</span><span class="plain-syntax">) </span><span class="identifier-syntax">FollowRulebook</span><span class="plain-syntax">(</span><span class="identifier-syntax">RB</span><span class="plain-syntax">, </span><span class="identifier-syntax">V</span><span class="plain-syntax">, </span><span class="identifier-syntax">F</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">a</span><span class="plain-syntax"> = </span><span class="identifier-syntax">latest_rule_result</span><span class="plain-syntax">--&gt;0;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">a</span><span class="plain-syntax"> == </span><span class="identifier-syntax">RS_FAILS</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">a</span><span class="plain-syntax"> == </span><span class="identifier-syntax">RS_SUCCEEDS</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">a</span><span class="plain-syntax"> = </span><span class="identifier-syntax">latest_rule_result</span><span class="plain-syntax">--&gt;1;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">a</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">latest_rule_result</span><span class="plain-syntax">--&gt;2;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">K</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">KindDefaultValue</span><span class="plain-syntax">(</span><span class="identifier-syntax">K</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">RulebookOutcomePrintingRule</span><span class="plain-syntax"> </span><span class="identifier-syntax">nro</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">nro</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"(no outcome)"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">print</span><span class="plain-syntax"> (</span><span class="reserved-syntax">string</span><span class="plain-syntax">) </span><span class="identifier-syntax">nro</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP5" class="paragraph-anchor"></a><b>&#167;5. Casting.</b>Nothing needs to be done to a rulebook value to make it a rule value.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">RULEBOOK_TY_to_RULE_TY</span><span class="plain-syntax"> </span><span class="identifier-syntax">r</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">r</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP6" class="paragraph-anchor"></a><b>&#167;6. Debugging.</b>Two modest routines to print out the names of rules and rulebooks when they
occur, in so far as memory economy allows this.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">DebugRulebooks</span><span class="plain-syntax"> </span><span class="identifier-syntax">subs</span><span class="plain-syntax"> </span><span class="identifier-syntax">parameter</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">spaces</span><span class="plain-syntax">(2*</span><span class="identifier-syntax">process_rulebook_count</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"["</span><span class="plain-syntax">, (</span><span class="identifier-syntax">RulePrintingRule</span><span class="plain-syntax">) </span><span class="identifier-syntax">subs</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">parameter</span><span class="plain-syntax">) </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">" / on O"</span><span class="plain-syntax">, </span><span class="identifier-syntax">parameter</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"]^"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">DB_Rule</span><span class="plain-syntax"> </span><span class="identifier-syntax">R</span><span class="plain-syntax"> </span><span class="identifier-syntax">N</span><span class="plain-syntax"> </span><span class="identifier-syntax">blocked</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">R</span><span class="plain-syntax">==0) </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"[Rule ~"</span><span class="plain-syntax">, (</span><span class="identifier-syntax">RulePrintingRule</span><span class="plain-syntax">) </span><span class="identifier-syntax">R</span><span class="plain-syntax">, </span><span class="string-syntax">"~ "</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">BasicInformKit</span><span class="plain-syntax">`</span><span class="identifier-syntax">NUMBERED_RULES_CFGF</span><span class="plain-syntax">) </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"("</span><span class="plain-syntax">, </span><span class="identifier-syntax">N</span><span class="plain-syntax">, </span><span class="string-syntax">") "</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">blocked</span><span class="plain-syntax"> == </span><span class="reserved-syntax">false</span><span class="plain-syntax">) </span><span class="string-syntax">"applies.]"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"does not apply (wrong "</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">blocked</span><span class="plain-syntax"> == </span><span class="constant-syntax">1</span><span class="plain-syntax">) </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"scene"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">blocked</span><span class="plain-syntax"> == </span><span class="constant-syntax">2</span><span class="plain-syntax">) </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"action"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">blocked</span><span class="plain-syntax"> == </span><span class="constant-syntax">3</span><span class="plain-syntax">) </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"actor"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">blocked</span><span class="plain-syntax"> == </span><span class="constant-syntax">4</span><span class="plain-syntax">) </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"context"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">").]^"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP7" class="paragraph-anchor"></a><b>&#167;7. The Default Rule and Rulebook.</b></p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">LITTLE_USED_DO_NOTHING_R</span><span class="plain-syntax">; </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">; ];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">EMPTY_RULEBOOK</span><span class="plain-syntax"> </span><span class="identifier-syntax">forbid_breaks</span><span class="plain-syntax">; </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">; ];</span>
</pre>
<nav role="progress"><div class="progresscontainer">
    <ul class="progressbar"><li class="progressprev"><a href="mstck.html">&#10094;</a></li><li class="progresssection"><a href="dftm.html">dftm</a></li><li class="progresssection"><a href="sttm.html">sttm</a></li><li class="progresssection"><a href="uttm.html">uttm</a></li><li class="progresssection"><a href="prgrp.html">prgrp</a></li><li class="progresssection"><a href="mttm.html">mttm</a></li><li class="progresssection"><a href="srtm.html">srtm</a></li><li class="progresssection"><a href="tbtm.html">tbtm</a></li><li class="progresssection"><a href="mstck.html">mstck</a></li><li class="progresscurrent">rltm</li><li class="progresssection"><a href="actm.html">actm</a></li><li class="progresssection"><a href="prtm.html">prtm</a></li><li class="progresssection"><a href="flx.html">flx</a></li><li class="progresssection"><a href="blckv.html">blckv</a></li><li class="progresssection"><a href="kntm.html">kntm</a></li><li class="progresssection"><a href="txtm.html">txtm</a></li><li class="progresssection"><a href="chtm.html">chtm</a></li><li class="progresssection"><a href="rgtm.html">rgtm</a></li><li class="progresssection"><a href="lstm.html">lstm</a></li><li class="progresssection"><a href="cmtm.html">cmtm</a></li><li class="progresssection"><a href="rkt.html">rkt</a></li><li class="progresssection"><a href="rltns.html">rltns</a></li><li class="progresssection"><a href="prtm2.html">prtm2</a></li><li class="progresssection"><a href="rttm.html">rttm</a></li><li class="progressnext"><a href="actm.html">&#10095;</a></li></ul></div>
</nav><!-- End of weave -->

		</main>
	</body>
</html>

